﻿
using Castle.DynamicProxy;
using InfrastructureBase.Base;
using InfrastructureBase.Base.AuthBase.JwtAuth;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;

namespace InfrastructureBase.Data.Aop
{
    public class JwtAuthAop : IInterceptor
    {
        private readonly IHttpContextAccessor httpContextAccessor;
        private readonly JwtConfig options;
        public JwtAuthAop(IHttpContextAccessor _httpContextAccessor,IOptionsSnapshot<JwtConfig> _options)
        {
            httpContextAccessor = _httpContextAccessor;
            options = _options?.Value;
        }

        public  void Intercept(IInvocation invocation)
        {
            #region MyRegion
            //httpContextAccessor.HttpContext.Request.Headers.TryGetValue("Token", out var token);
            //if (token.ToString() != "XXXXXX")
            //{

            //}
            #endregion
            Task<string> tokenTask = httpContextAccessor.HttpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "Token");
            string token = tokenTask.Result;

           

        }
    }
}
